package com.xueyi.aixihu.utils;

import org.redisson.api.RReadWriteLock;
import redis.clients.jedis.Jedis;

/**
 * @author LuQi
 * @类描述 最终工具类
 * @时间 2021/6/21
 */
public class FinalUtil {


    public static void unLockAndCloseRedis(Jedis jedis, RReadWriteLock... readWriteLocks) {

        if (jedis != null) {
            jedis.close();
        }

        if (readWriteLocks != null && readWriteLocks.length > 0) {


            for (RReadWriteLock readWriteLock : readWriteLocks) {
                try {

                    if (readWriteLock.readLock().getHoldCount() > 0) {
                        readWriteLock.readLock().unlock();
                    }
                } catch (Exception e) {
                }
                try {
                    if (readWriteLock.writeLock().getHoldCount() > 0) {
                        readWriteLock.writeLock().unlock();
                    }
                } catch (Exception e) {
                }
            }

        }

    }

}
